<?php

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$oss= require __DIR__ . '/qiniu.php';

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],

    'timeZone'=>'Asia/Shanghai',
    'defaultRoute'=>'/site/index',

    'modules' => [
        'index' => [
            'class' => 'app\modules\index\Index',
        ],
        'user' => [
            'class' => 'app\modules\user\User',
        ],
        'merchant' => [
            'class' => 'app\modules\merchant\Merchant',
        ],
        'admin' => [
            'class' => 'app\modules\admin\Admin',
        ],
        'pay' => [
            'class' => 'app\modules\pay\Pay',
        ],
    ],

    'controllerMap' => [
        //公共上传
        'upload' => 'app\common\controllers\UploadController',
    ],

    'components' => [
        'task_queue' => require __DIR__ . '/queue/task_queue.php',
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'Je2ELmFyMfd9651NCsOVS9DkppXAX435345wefwef',
            'enableCsrfCookie' => false,
            'enableCsrfValidation'=> false,
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
                'multipart/form-data' => 'yii\web\MultipartFormDataParser'
            ]
        ],
        'response'=>[
            'class'=>'app\components\response\Response',
            'format'=>'json',
        ],
        'oss'=>$oss,
        'jwt' => [
            'class' => 'sizeg\jwt\Jwt',
            'key'   => '456456159',
        ],
        'wechat' => [
            'class' => 'jianyan\easywechat\Wechat',
            'userOptions' => [],  // 用户身份类参数
            'sessionParam' => 'wechatUser', // 微信用户信息将存储在会话在这个密钥
            'returnUrlParam' => '_wechatReturnUrl', // returnUrl 存储在会话中
            'rebinds' => [ // 自定义服务模块
                // 'cache' => 'common\components\Cache',
            ]
        ],
        'i18n' => [
            'translations' => [
                'app*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                ],
            ],
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'flushInterval'=>1,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning','info'],
                    'logFile'=>'@runtime/logs/app.log'
                ],
            ],
        ],
        'db' => $db,
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ],
        ],
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
//    $config['bootstrap'][] = 'debug';
//    $config['modules']['debug'] = [
//        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
//    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'generators'=>[
            'queue'=>[
                'class'=>'yii\queue\gii\Generator'
            ]
        ],
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}

return $config;
